package com.design.oop.bean;

import java.util.ArrayList;

import com.design.oop.R;

public class WheatBeerKind {
	private int drawableId;
	private String englishName;
	private String koreanName;
	private BeerType beerType;
	private float degree;
	private Country country;
	private float rate;
	private String fileName;
	private int width;
	private int height;
	private String imageUrl;

	public static final ArrayList<WheatBeerKind> BEER_LIST;

	static {
		BEER_LIST = new ArrayList<WheatBeerKind>();
		//http://www.ratebeer.com/beer/weihenstephaner-hefe-weissbier/1156/
		BEER_LIST.add(new WheatBeerKind(R.drawable.original_weizen, "5.0 Original Weizen", "5.0 오리지널 바이젠", BeerType.HEFE, 5.0f, Country.GERMAN, 2.57f, "original_weizen"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_arcobrau, "Arcobrau Weissbier Hell", "아르코브로이 바이스비어 헬", BeerType.HEFE, 5.3f, Country.GERMAN, 3.07f, "new_arcobrau"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_edelweiss, "Edelweiss Weissbier Snowfresh", "에델바이스 바이스비어 스노우프레시", BeerType.HEFE, 5.0f, Country.AUSTRIA, 3.26f, "new_edelweiss"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.erdinger, "ERDINGER Weissbier", "에딩거 바이스비어", BeerType.HEFE, 5.3f, Country.GERMAN, 3.12f, "erdinger"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_hoegaarden, "Hoegaarden Witbier-Biere Blanche", "호가든", BeerType.HEFE, 4.9f, Country.BEGIUM, 3.52f, "new_hoegaarden"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_kaiserdom, "Kaiserdom Hefe-weissbier", "카이저돔 헤페바이스비어", BeerType.HEFE, 4.7f, Country.GERMAN, 2.71f, "new_kaiserdom"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.konig_ludwig, "Konig Ludwig Weissbier Hell", "쾨니히 루드비히 바이스 비어 헬", BeerType.HEFE, 5.5f, Country.GERMAN, 0.0f, "konig_ludwig"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.krombacher_weizen, "Krombacher Weizen", "크롬바커 바이젠", BeerType.HEFE, 5.3f, Country.GERMAN, 3.01f, "krombacher_weizen"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_maisel, "Maisel's Weisse Original", "마이셀 바이스", BeerType.HEFE, 5.2f, Country.GERMAN, 3.51f, "new_maisel"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.oettinger, "OeTTINGER Hefeweissbier", "웨팅어 헤페바이스", BeerType.HEFE, 4.9f, Country.GERMAN, 2.66f, "oettinger"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_paulaner, "PAULANER Hefe-Weissbier", "파울라너 헤페바이스", BeerType.HEFE, 5.5f, Country.GERMAN, 3.59f, "new_paulaner"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_schmucker, "Schmucker Hefeweizen", "슈무커 헤페바이젠", BeerType.HEFE, 5.0f, Country.GERMAN, 2.95f, "new_schmucker"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_schneider, "Schneider Weisse TAP7 Unser Original", "슈나이더 바이스 운저 오리지널 TAB 7", BeerType.HEFE, 5.4f, Country.GERMAN, 3.57f, "new_schneider"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.thuringer, "Thuringer Premium Hefeweizen", "튀링어 프리미엄 헤페바이젠", BeerType.HEFE, 4.6f, Country.GERMAN, 2.57f, "thuringer"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_tucher, "Tucher Helles Hefe Weizen", "투허 헬레스 헤페 바이젠", BeerType.HEFE, 5.35f, Country.GERMAN, 3.25f, "new_tucher"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.new_weihenstephaner, "Weihenstephaner Hefe Weissbier", "바이엔슈테판 헤페바이스", BeerType.HEFE, 5.4f, Country.GERMAN, 3.8f, "new_weihenstephaner"));
		BEER_LIST.add(new WheatBeerKind(R.drawable.willianbrau, "Willianbrau Weizen", "윌리안 브로이 바이젠", BeerType.HEFE, 5.0f, Country.BEGIUM, 2.53f, "willianbrau"));
	}

	private enum BeerType {
		LAGER(0), ALE(1), HEFE(2);

		private int beerType;

		BeerType(int beerType) {
			this.beerType = beerType;
		}

		public int getValue() {
			return this.beerType;
		}
	}

	public enum Country {
		GERMAN("독일"), BEGIUM("벨기에"), AUSTRIA("오스트리아");

		private String country;

		Country(String country) {
			this.country = country;
		}

		public String getValue() {
			return this.country;
		}
	}

	public enum SortType {
		ENAME(0), RATE(1), DEGREE(2);

		private int sortType;

		SortType(int sortType) {
			this.sortType = sortType;
		}

		public int getValue() {
			return this.sortType;
		}

		public static SortType of(int sortType) {
			if (RATE.getValue() == sortType) {
				return RATE;
			} else if (DEGREE.getValue() == sortType) {
				return DEGREE;
			}
			return ENAME;
		}
	}

	public WheatBeerKind() {

	}

	public WheatBeerKind(int drawableId, String englishName, String koreanName, BeerType beerType, Float degree, Country country, Float rate, String fileName) {
		this.setDrawableId(drawableId);
		this.setEnglishName(englishName);
		this.setKoreanName(koreanName);
		this.setBeerType(beerType);
		this.setDegree(degree);
		this.setCountry(country);
		this.setRate(rate);
		this.setFileName(fileName);
	}

	public static int getDrawableIdByIndex(int index) {
		index = Math.min(BEER_LIST.size() - 1, index);
		index = Math.max(0, index);
		return BEER_LIST.get(index).drawableId;
	}

	public static int getIndexByDrawableId(int id) {
		for (int i = 0; i < BEER_LIST.size(); i++) {
			WheatBeerKind beer = BEER_LIST.get(i);
			if (beer.getDrawableId() == id) {
				return i;
			}
		}

		return 0;
	}

	public static WheatBeerKind getBeerByDrawable(int id) {
		for (WheatBeerKind beer : BEER_LIST) {
			if (beer.getDrawableId() == id) {
				return beer;
			}
		}

		return null;
	}

	public static WheatBeerKind getBeerByFileName(String fileName) {
		for (int i = 0; i < BEER_LIST.size(); i++) {
			WheatBeerKind beer = BEER_LIST.get(i);
			String originFileName = beer.fileName + ".png";
			if (originFileName.equals(fileName)) {
				return beer;
			}
		}

		return null;
	}

	public int getDrawableId() {
		return drawableId;
	}

	public void setDrawableId(int drawableId) {
		this.drawableId = drawableId;
	}

	public String getEnglishName() {
		return englishName;
	}

	public void setEnglishName(String englishName) {
		this.englishName = englishName;
	}

	public String getKoreanName() {
		return koreanName;
	}

	public void setKoreanName(String koreanName) {
		this.koreanName = koreanName;
	}

	public BeerType getBeerType() {
		return beerType;
	}

	public void setBeerType(BeerType beerType) {
		this.beerType = beerType;
	}

	public Float getDegree() {
		return degree;
	}

	public void setDegree(Float degree) {
		this.degree = degree;
	}

	public Country getCountry() {
		return country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	public Float getRate() {
		return rate;
	}

	public void setRate(Float rate) {
		this.rate = rate;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getImageHeight(int columnWidth) {
		// TODO 가로/세로가 너무 작은 이미지는 늘리지 않고 원본 사이즈로 보여주도록 해야함
		/*if (getWidth() < columnWidth) {
			return getHeight();
		}*/
		float itemRatio = (float)getHeight() / (float)getWidth();
		return (int)Math.ceil(itemRatio * (float)((columnWidth)));
	}

	public String getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}
}
